#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Python基础：控制流程
"""

def demonstrate_if_else():
    """演示if-else条件语句"""
    score = 85
    
    if score >= 90:
        grade = "A"
    elif score >= 80:
        grade = "B"
    elif score >= 70:
        grade = "C"
    elif score >= 60:
        grade = "D"
    else:
        grade = "F"
    
    print(f"分数: {score}, 等级: {grade}")

def demonstrate_for_loop():
    """演示for循环"""
    # 遍历列表
    fruits = ["苹果", "香蕉", "橙子", "葡萄"]
    print("水果列表:")
    for fruit in fruits:
        print(f"  - {fruit}")
    
    # 使用range函数
    print("\n使用range函数:")
    for i in range(5):
        print(f"  数字: {i}")
    
    # 带步长的range
    print("\n带步长的range:")
    for i in range(0, 10, 2):
        print(f"  偶数: {i}")

def demonstrate_while_loop():
    """演示while循环"""
    count = 0
    print("while循环计数:")
    while count < 5:
        print(f"  计数: {count}")
        count += 1
    
    # 使用break和continue
    print("\n使用break和continue:")
    for i in range(10):
        if i == 3:
            continue  # 跳过当前迭代
        if i == 7:
            break     # 退出循环
        print(f"  数字: {i}")

def demonstrate_nested_loops():
    """演示嵌套循环"""
    print("嵌套循环 - 九九乘法表:")
    for i in range(1, 4):  # 简化为1-3
        for j in range(1, 4):
            result = i * j
            print(f"  {i} × {j} = {result}", end="  ")
        print()  # 换行

if __name__ == "__main__":
    print("=== if-else条件语句示例 ===")
    demonstrate_if_else()
    print("\n=== for循环示例 ===")
    demonstrate_for_loop()
    print("\n=== while循环示例 ===")
    demonstrate_while_loop()
    print("\n=== 嵌套循环示例 ===")
    demonstrate_nested_loops()